/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package general.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import jpa.controller.DetalheJpaController;
import jpa.entity.Detalhe;
/**
 *
 * @author isaias
 */

@FacesConverter(value="detalheConverter")
public class DetalheConverter implements Converter{
     public Object getAsObject(FacesContext fc, UIComponent uic, String name) { 
            Detalhe detalhe = new DetalheJpaController().findDetalheByName(name);
        return detalhe;
    }

    public String getAsString(FacesContext fc, UIComponent uic, Object o) {
            if(o instanceof Detalhe){
                return ((Detalhe)o).getName();
            }
        return null;
    }
}
